package com.umeox.watch.moto.launcher.ui;


import static com.umeox.watch.moto.pedometer.util.ICache.KEY_LANGUAGE;

import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.umeox.moto.common.utils.LanguageConfig;
import com.umeox.moto.common.utils.SystemUtils;
import com.umeox.moto.watch.themes.app.ThemeAppCompatActivity;
import com.umeox.watch.moto.launcher.R;
import com.umeox.watch.moto.launcher.adapter.LanguageChooseAdapter;
import com.umeox.moto.watch.themes.LanguageBean;
import com.umeox.watch.moto.pedometer.util.CacheImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

public class ChooseLanguageActivity extends ThemeAppCompatActivity {
    final List<LanguageBean> list = new ArrayList<>();
    private LanguageChooseAdapter mAdapter;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_language_choose);
        RecyclerView languageRv = findViewById(R.id.rv_language);
        findViewById(R.id.iv_next).setOnClickListener(v -> {
            CacheImpl.getInstance().put(KEY_LANGUAGE, true);
            final Locale selectedLanguage = mAdapter.getSelectedLanguage();
            SystemUtils.setLocalLanguage(selectedLanguage);
            startActivity(new Intent(ChooseLanguageActivity.this, DetectSimCardActivity.class));
            finish();
        });
        final Locale[] locales = LanguageConfig.LOCALE_IQIBLA_KID;
        for (Locale value : locales) {
            final LanguageBean languageBean = new LanguageBean();
            languageBean.setLocale(value);
            languageBean.setSelection(Locale.getDefault().equals(value));
            list.add(languageBean);
        }

        languageRv.setHasFixedSize(true);
        languageRv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        mAdapter = new LanguageChooseAdapter(list, null);
        languageRv.setAdapter(mAdapter);
    }

    @Override
    public void onBackPressed() {

    }
}
